﻿
@{
    ViewData["Title"] = "爬取的文章列表";
    ViewData["container-css"] = "col-md-12";
    var save_count = (int)ViewData["save-count"];
    var not_save_count = (int)ViewData["not-save-count"];
    var is_save = (bool)ViewData["is_save"];
    var page = ViewData["page"] as PageModel;
    var list = ViewData["list"] as List<article_crawler>;
    var cateList = ViewData["cate"] as List<article_category>;
}

@section search{
    @Html.Partial("_ManageSearch", new KeyValuePair<string, string>("输入标题,标签,URL等内容搜索", ViewData["search"].ToString()))
}

<div class="row">
    <div class="col-md-12">
        <ul id="tab-div" class="nav nav-tabs" role="tablist">
            <li class="@(is_save?"active":"")"><a href="@Url.Action("SaveList")" role="tab">已保存的文章 <i class="fa">@save_count</i> </a></li>
            <li class="@(is_save?"":"active")"><a href="@Url.Action("List")" role="tab">待收录的文章<i class="fa">@not_save_count</i> </a></li>
        </ul>

        <div class="margin-top-10"></div>

        <div id="div-tab-list" class="tab-content">
            <div id="div-show" class="tab-pane active">
                <table class="@ViewHelper.Standard_table_css">
                    <thead>
                        <tr>
                            <th data-column-name="@nameof(article_crawler.title)">标题</th>
                            <th data-column-name="@nameof(article_category.category_name)">分类名称</th>
                            <th data-column-name="@nameof(article_crawler.tag)">文章标签</th>
                            <th data-column-name="@nameof(article_crawler.url)">来源</th>
                            <th data-column-name="@nameof(article_crawler.img)">封面图片</th>
                            <th data-column-name="@nameof(article_crawler.publish_date)">发布时间</th>
                            <th data-column-name="@nameof(article_crawler.create_time)">创建时间</th>
                            <th data-column-name="@nameof(article_crawler.last_update)">更新时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            if (list.Count > 0)
                            {
                                foreach (var item in list)
                                {
                                    var cate = cateList.FirstOrDefault(x => x.id == item.cateid) ?? new article_category();
                                    var href = Url.Action("Detail", new { id = item.id });
                                    <tr data-id="@item.id">
                                        <td><a href="@href">@item.title</a></td>
                                        <td title="@cate.id">@cate.category_name</td>
                                        <td>
                                            @{
                                                if (!string.IsNullOrWhiteSpace(item.tag))
                                                {
                                                    var tags = JsonConvert.DeserializeObject<List<string>>(item.tag);
                                                    foreach (var tag in tags)
                                                    {
                                                        <span>@tag </span>
                                                    }
                                                }
                                            }
                                        </td>
                                        <td><a href="@item.url" target="_blank">@item.url</a></td>
                                        <td>
                                            @if (!string.IsNullOrWhiteSpace(item.img))
                                            {
                                                <a href="@item.img" target="_blank">查看封面图片</a>
                                            }
                                        </td>
                                        <td>@item.publish_date.ToLocalDateTimeString()</td>
                                        <td>@item.create_time.ToLocalDateTimeString()</td>
                                        <td>@item.last_update.ToLocalDateTimeString()</td>
                                    </tr>
                                }
                            }
                            else
                            {
                                @Html.Raw(ViewHelper.Standard_no_record_tr)
                            }
                        }
                    </tbody>
                </table>
                @Html.Partial("Pagination", page)
            </div>
        </div>
    </div>
</div>